-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
31 lines (24 loc) · 882 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.Arrays;
import java.util.Scanner;
public class AnagramChecker {
public static boolean areAnagrams(String str1, String str2) {
if (str1.length() != str2.length())
return false;
char[] arr1 = str1.toCharArray();
char[] arr2 = str2.toCharArray();
Arrays.sort(arr1);
Arrays.sort(arr2);
return Arrays.equals(arr1, arr2);
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the first string: ");
String str1 = scanner.nextLine();
System.out.print("Enter the second string: ");
String str2 = scanner.nextLine();
if (areAnagrams(str1, str2))
System.out.println("The strings are anagrams.");
else
System.out.println("The strings are not anagrams.");
}
}